package designpatterns.singleton;

/**
 * @program: MyTank
 * @description:
 * @author: 王术平
 * @create: 2021-01-05 19:22
 **/
public class SingleTonByDoubleCheck {
    private static volatile/*防指令重排序导致有线程获取到未初始化完成的对象*/ SingleTonByDoubleCheck instance = null;

    private SingleTonByDoubleCheck() {
    }

    public static SingleTonByDoubleCheck getInstance() {
        if (instance == null) {
            synchronized (SingleTonByDoubleCheck.class) {
                if (instance == null) {
                    instance = new SingleTonByDoubleCheck();
                }
            }
        }
        return instance;
    }
}
